class User < ActiveRecord::Base
	belongs_to :room
	
	validates_uniqueness_of :login 
	validates_presence_of :login 
	validates_presence_of :password
	
	def self.authenticate login, password
		user = self.find_by_login(login)
		return user if user and user.password == password
		return nil
	end
	
	def position
		return self.room.players.index(self)
	end
end
